package com.demo.jvm.structure.constant.parser;

import com.demo.jvm.structure.constant.CONSTANT_info;

import java.io.DataInputStream;
import java.nio.charset.StandardCharsets;

public class CONSTANT_info_Parser {

    public CONSTANT_info parse(int tag, DataInputStream dis, int tableIndex) {
        switch (tag) {
            case 1: {
                return new CONSTANT_Utf8_info_Parser(dis).readValue(tableIndex);
            }
            case 3: {
                return new CONSTANT_Integer_info_Parser(dis).readValue(tableIndex);
            }
            case 4: {
                return new CONSTANT_Float_info_Parser(dis).readValue(tableIndex);
            }
            case 5: {
                return new CONSTANT_Long_info_Parser(dis).readValue(tableIndex);
            }
            case 6: {
                return new CONSTANT_Double_info_Parser(dis).readValue(tableIndex);
            }
            case 7: {
                return new CONSTANT_Class_info_Parser(dis).readValue(tableIndex);
            }
            case 8: {
                return new CONSTANT_String_info_Parser(dis).readValue(tableIndex);
            }
            case 9: {
                return new CONSTANT_Fieldref_info_Parser(dis).readValue(tableIndex);
            }
            case 10: {
                return new CONSTANT_Methodref_info_Parser(dis).readValue(tableIndex);
            }
            case 11: {
                return new CONSTANT_InterfaceMethodref_info_Parser(dis).readValue(tableIndex);
            }
            case 12: {
                return new CONSTANT_NameAndType_info_Parser(dis).readValue(tableIndex);
            }
            case 15: {
                return new CONSTANT_Method_Handle_info_Parser(dis).readValue(tableIndex);
            }
            case 16: {
                return new CONSTANT_Method_Type_info_Parser(dis).readValue(tableIndex);
            }
            case 18: {
                return new CONSTANT_Invoke_Dynamic_info_Parser(dis).readValue(tableIndex);
            }
            default: {
                return null;
            }
        }
    }
}
